package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.OrderSetting;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface OrderSettingMapper extends BaseMapper<OrderSetting> {
    @Select("select  day(orderdate) as date , number ,reservations  from  t_ordersetting  where  ORDERDATE BETWEEN #{beginDate} and #{endDate}")
    List<Map> findOrderSettingsData(@Param("beginDate") String beginDate, @Param("endDate") String endDate);

    @Select("select count(1) from t_ordersetting where ORDERDATE = #{orderDate} and  number>RESERVATIONS")
    int isOrderOk(@Param("orderDate") String orderDate);

    @Update("UPDATE t_ordersetting SET RESERVATIONS=RESERVATIONS+1 WHERE ORDERDATE = #{orderDate}")
    void updateReservationsByOrderDate(@Param("orderDate") String orderDate);

}
